package com.ruoyi.user.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.user.domain.CheUser;
import com.ruoyi.user.service.CheUserService;
import com.ruoyi.user.util.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class CheUserController {
    @Autowired
    CheUserService cheUserService;

    @RequestMapping("/login")
    public R login(@RequestBody CheUser cheUser){
        CheUser cheUser1 = cheUserService.lambdaQuery().eq(CheUser::getPhone,cheUser.getPhone()).one();
            if (cheUser1 != null && cheUser.getPassword().equals(cheUser1.getPassword())){
                String token = JwtUtil.createJWT(cheUser1.getId()+"");
                System.out.println(token);
                return R.ok(token,"登陆成功!");
            }
        return R.fail("登陆失败!");

    }
    @RequestMapping("/getInfo")
    public R getInfo(){
        return R.ok();
    }



}
